package com.baitiaojun.bulletscreen.service.impl;

import com.baitiaojun.api.domain.video.BulletScreenMqDuplicate;
import com.baitiaojun.api.exception.ConditionException;
import com.baitiaojun.bulletscreen.mapper.BulletScreenMqDuplicateMapper;
import com.baitiaojun.bulletscreen.service.BulletScreenMqDuplicateService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @类名 BulletScreenMqDuplicateServiceImpl
 * @描述 TODO
 * @作者 白条君
 * @创建日期 2023/1/3 14:37
 * @版本 1.0
 */
@Transactional
@Service
public class BulletScreenMqDuplicateServiceImpl implements BulletScreenMqDuplicateService {

    @Resource
    private BulletScreenMqDuplicateMapper duplicateMapper;

    @Override
    public void saveBulletScreenMqDuplicate(BulletScreenMqDuplicate bulletScreenMqDuplicate) throws ConditionException {
        int res = duplicateMapper.insertSelective(bulletScreenMqDuplicate);
        if (res == 0) {
            throw new ConditionException("添加冗余存储失败");
        }
    }

    @Override
    public boolean isExists(Long id) {
        Integer exists = duplicateMapper.isExists(id);
        return ObjectUtils.isNotEmpty(exists);
    }

    @Override
    public void updateBulletScreenMqDuplicate(BulletScreenMqDuplicate bulletScreenMqDuplicate) throws ConditionException {
        int res = duplicateMapper.updateBulletScreenMqDuplicate(bulletScreenMqDuplicate);
        if (res == 0) {
            throw new ConditionException("更新冗余存储失败");
        }
    }

    @Override
    public List<BulletScreenMqDuplicate> getBulletScreenMqDuplicate(String status) {
        return duplicateMapper.selectByStatus(status);
    }

    @Override
    public void batchUpdateBulletScreenMqDuplicate(List<BulletScreenMqDuplicate> bulletScreenMqDuplicate) throws ConditionException {
        int res = duplicateMapper.batchUpdateBulletScreenMqDuplicate(bulletScreenMqDuplicate);
        if (res == 0) {
            throw new ConditionException("批量更新冗余存储失败");
        }
    }
}
